<template>
  <div class="backend-fullscreen">
    <el-header class="site-header">
      <div class="header-content">
        <div class="site-logo">
          <span class="logo-text">博客后台管理</span>
        </div>
        <div class="header-actions">
          <el-button class="auth-btn" type="primary" plain @click="goHome">返回首页</el-button>
          <span class="welcome-text">欢迎，{{ username }}</span>
          <el-button class="auth-btn" type="danger" plain @click="handleLogout">退出</el-button>
        </div>
      </div>
    </el-header>

    <div class="backend-container">
      <div class="sidebar">
        <el-menu
          :default-active="activeMenu"
          class="el-menu-vertical"
          @select="handleSelect"
          text-color="#333"
          active-text-color="#3273dc"
        >
          <el-menu-item index="/backend/dashboard" v-if="isAdmin">
            <el-icon><DataLine /></el-icon>
            <span>数据仪表盘</span>
          </el-menu-item>
          <el-menu-item index="/backend">
            <el-icon><Document /></el-icon>
            <span>文章管理</span>
          </el-menu-item>
          <el-menu-item index="/backend/categories" v-if="isAdmin">
            <el-icon><Files /></el-icon>
            <span>分类管理</span>
          </el-menu-item>
          <el-menu-item index="/backend/audit" v-if="isAdmin">
            <el-icon><Check /></el-icon>
            <span>文章审核</span>
          </el-menu-item>
          <el-menu-item index="/backend/users" v-if="isAdmin">
            <el-icon><User /></el-icon>
            <span>用户管理</span>
          </el-menu-item>
        </el-menu>
      </div>

      <div class="main-content">
        <div class="welcome-banner">
          <div class="banner-content">
            <h2 class="banner-title">{{ pageTitle }}</h2>
            <p class="banner-text">轻松管理您的博客内容</p>
          </div>
          <div class="banner-image">
            <el-icon class="banner-icon" :size="60"><Document /></el-icon>
          </div>
        </div>
        
        <router-view />
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { ElMessage } from 'element-plus'
import { Document, Files, Check, DataLine, User } from '@element-plus/icons-vue'

const router = useRouter()
const route = useRoute()

const username = ref(localStorage.getItem('username') || '')
const isAdmin = ref(localStorage.getItem('role') === 'ADMIN')

const activeMenu = computed(() => route.path)

const pageTitle = computed(() => {
  const path = route.path
  if (path === '/backend') return '文章管理'
  if (path === '/backend/categories') return '分类管理'
  if (path === '/backend/audit') return '文章审核'
  if (path === '/backend/dashboard') return '数据仪表盘'
  if (path === '/backend/users') return '用户管理'
  return '博客后台'
})

const handleSelect = (index) => {
  router.push(index)
}

const handleLogout = () => {
  localStorage.removeItem('token')
  localStorage.removeItem('username')
  localStorage.removeItem('role')
  ElMessage.success('退出成功')
  router.push('/')
}

const goHome = () => {
  router.push('/')
}
</script>

<style scoped>
.backend-fullscreen {
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: #f5f7fa;
  background-image: 
    radial-gradient(circle at 25% 15%, rgba(50, 115, 220, 0.05) 2%, transparent 15%),
    radial-gradient(circle at 75% 85%, rgba(74, 138, 244, 0.05) 2%, transparent 15%),
    radial-gradient(circle at 85% 25%, rgba(100, 161, 255, 0.07) 2%, transparent 15%),
    radial-gradient(circle at 15% 75%, rgba(74, 138, 244, 0.05) 2%, transparent 15%);
  background-size: 60px 60px, 80px 80px, 70px 70px, 90px 90px;
  background-position: 0 0, 0 0, 0 0, 0 0;
}

.site-header {
  height: 60px;
  padding: 0 20px;
  background: linear-gradient(90deg, #3273dc, #4a8af4);
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.15);
  color: white;
  position: relative;
  z-index: 10;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
  max-width: 1400px;
  margin: 0 auto;
}

.site-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.logo-text {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: 1px;
  background: linear-gradient(45deg, #ffffff, #e0e0e0);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.welcome-text {
  color: white;
  margin: 0 10px;
  font-weight: 500;
}

.auth-btn {
  border-radius: 4px;
  font-weight: 500;
}

.backend-container {
  display: flex;
  height: calc(100vh - 60px);
  overflow: hidden;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  position: relative;
  z-index: 5;
}

.sidebar {
  width: 240px;
  padding: 20px 15px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(5px);
  border-right: 1px solid rgba(234, 234, 234, 0.7);
  height: 100%;
  overflow-y: auto;
  box-shadow: 2px 0 5px rgba(0, 0, 0, 0.03);
  border-radius: 0 0 0 10px;
}

.el-menu {
  border-right: none;
  background: transparent;
}

.el-menu-item {
  border-radius: 6px;
  margin-bottom: 5px;
}

.main-content {
  flex: 1;
  padding: 25px;
  overflow-y: auto;
  position: relative;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(5px);
  display: flex;
  flex-direction: column;
}

.main-content::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: url('data:image/svg+xml,%3Csvg width="60" height="60" viewBox="0 0 60 60" xmlns="http://www.w3.org/2000/svg"%3E%3Cg fill="none" fill-rule="evenodd"%3E%3Cg fill="%239C92AC" fill-opacity="0.03"%3E%3Cpath d="M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z"/%3E%3C/g%3E%3C/g%3E%3C/svg%3E');
  z-index: -1;
  opacity: 0.5;
  border-radius: 0 0 10px 0;
}

.welcome-banner {
  background: linear-gradient(135deg, #3273dc, #6fa8dc);
  border-radius: 12px;
  padding: 20px 30px;
  margin-bottom: 25px;
  color: white;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
  overflow: visible;
  position: relative;
  width: 100%;
}

.banner-content {
  position: relative;
  z-index: 1;
  flex: 1;
  max-width: 80%;
}

.banner-title {
  font-size: 1.8rem;
  font-weight: 600;
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: visible;
}

.banner-text {
  font-size: 1rem;
  opacity: 0.9;
}

.banner-image {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.banner-icon {
  color: rgba(255, 255, 255, 0.2);
  font-size: 60px;
}

.welcome-banner::before {
  content: '';
  position: absolute;
  top: -50px;
  right: -50px;
  width: 200px;
  height: 200px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
}

.welcome-banner::after {
  content: '';
  position: absolute;
  bottom: -80px;
  left: -50px;
  width: 180px;
  height: 180px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 50%;
}
</style> 